package com.pine.manager.pineframework.trigger;

import com.pine.common.beans.pineframework.request.SysRoleAssignMenuRequest;
import com.pine.common.beans.pineframework.request.SysRoleSaveOrUpdateRequest;
import com.pine.common.beans.pineframework.request.SysRoleUpdateStatusRequest;
import com.pine.common.beans.request.BatchIdRequest;
import com.pine.common.beans.response.DeleteResponse;
import com.pine.common.trigger.TriggerContext;
import com.pine.common.trigger.TriggerUtil;
import com.pine.manager.core.TriggerTypeEnum;

/**
 * <p>
 * 角色 触发器管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-08-13
 */
public class SysRoleTriggerManager {

    /**
     * 新增或修改
     *
     * @param request 请求体
     * @return 响应体
     */
    public static Boolean saveOrUpdate(SysRoleSaveOrUpdateRequest request) {
        TriggerContext<SysRoleSaveOrUpdateRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_ROLE_SAVE_OR_UPDATE, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }

    /**
     * 删除
     *
     * @param request 请求体
     * @return 响应体
     */
    public static DeleteResponse delete(BatchIdRequest<Long> request) {
        TriggerContext<BatchIdRequest<Long>> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_ROLE_DELETE, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }

    /**
     * 修改状态
     *
     * @param request 请求体
     * @return 响应体
     */
    public static Boolean updateStatus(SysRoleUpdateStatusRequest request) {
        TriggerContext<SysRoleUpdateStatusRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_ROLE_UPDATE_STATUS, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }

    /**
     * 给角色分配菜单
     *
     * @param request 请求体
     * @return 响应体
     */
    public static Boolean assignMenu(SysRoleAssignMenuRequest request) {
        TriggerContext<SysRoleAssignMenuRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_ROLE_ASSIGN_MENU, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }
}
